<%--
  Created by IntelliJ IDEA.
  User: 周宏硕
  Date: 2018/11/13
  Time: 16:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>login</title>
</head>
<body>

<h1>插入一条管理员</h1>
<form action="/ManagerController/addManager" method="POST" id="form_login">
    <p>用户名：</p><input type="text" name="managerName" id="managerName">
    <p>密码：</p><input type="password" id="pass_temp">
    <input type="hidden" name="managerPass" id="ManagerPass">

    <button type="button" id="btn_login">插入</button>
    
</form>



<h1>查询是否成功</h1>
<form action="/ManagerController/loginRSA"  method="post">
    <p>用户名：</p><input type="text" name="managerName">
    <p>密码：</p><input type="password"name="managerPass">
    <input type="submit" value="提交">

</form>


</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script type="application/javascript" src="/js/security.js"></script>
<script>

   $(function () {
       $("#btn_login").click(function(){
           var password=$("#pass_temp").val();
           if (password!=""){
               var  pas=rasEncrypl(password);
               $("#ManagerPass").val(pas);
               console.log("未加密"+password)
               console.log("加密"+pas)
               $("#form_login").submit();
           }
       })
   })


function  rasEncrypl(str) {
    var enerypedPwd="";
    $.ajax({
      url:"generateRSAJsKey",
        async:false,
        success:function (result) {
             if(result!=null){
                 //加密模块
                 var Modulus=result.split(';')[0];
                 //公匙指数
                 var public_exponent=result.split(';')[1];
                 //通过摸和公匙参数回去公匙
                 var key=new RSAUtils.getKeyPair(public_exponent,"",Modulus);
                 //颠倒密码的顺序，解密后发现密码顺序是反的
                 var reversedPwd=str.split("").reverse().join("");
                 //对密码进行加密传输
                 enerypedPwd=RSAUtils.encryptedString(key,reversedPwd);

             }

        },
        error : function() {
            alert("请求异常")
        }

    })

   return enerypedPwd;
}


</script>
</html>
